import { configure, getLogger, Logger } from "log4js";
class log4_js {
    private static instance: log4_js
    public log: Logger
    private constructor() {
        configure({
            appenders: {
                cheese: {
                    type: "dateFile",
                    pattern: "yyyy-MM-dd.log",
                    filename: "./log/log",
                    category: "default",
                    alwaysIncludePattern: true
                },
                console: {
                    //控制台输出,删掉控制台将不输出
                    type: "console",
                },
                //info正常配置
                infoFile: {
                    type: "dateFile",
                    filename: "log/info",
                    pattern: "yyyy-MM-dd.log",
                    alwaysIncludePattern: true
                },
                info: {
                    type: "logLevelFilter",
                    level: "info",
                    maxLevel: "info",
                    appender: "infoFile"
                },
                //warn警告配置
                warnFile: {
                    type: "dateFile",
                    filename: "log/warn",
                    pattern: "yyyy-MM-dd.log",
                    alwaysIncludePattern: true
                },
                warn: {
                    type: "logLevelFilter",
                    level: "warn",
                    maxLevel: "warn",
                    appender: "warnFile"
                },
                //error错误配置
                errorFile: {
                    type: "dateFile",
                    filename: "log/error",
                    pattern: "yyyy-MM-dd.log",
                    alwaysIncludePattern: true
                },
                errors: {
                    type: "logLevelFilter",
                    level: "error",
                    maxLevel: "error",
                    appender: "errorFile"
                },
                //fatal致命错误配置
                fatalFile: {
                    type: "dateFile",
                    filename: "log/fatal",
                    pattern: "yyyy-MM-dd.log",
                    alwaysIncludePattern: true
                },
                fatal: {
                    type: "logLevelFilter",
                    level: "fatal",
                    maxLevel: "fatal",
                    appender: "fatalFile"
                }
            },
            categories: {
                default: {
                    appenders: ["console", "fatal", "errors", "warn", "info"],
                    level: "all"
                },
            }
        })
        this.log = getLogger('日志')
    }
    /**
     * 获取单例
     */
    public static getInstance() {
        if (!this.instance) {
            this.instance = new log4_js()
            return this.instance
        } else {
            return this.instance
        }

    }
}
export let log4js:Logger = log4_js.getInstance().log